//
//  LJJTimeTwoButtonView.m
//  shopTest
//
//  Created by 梁佳佳 on 2016/11/17.
//  Copyright © 2016年 梁佳佳. All rights reserved.
//

#import "LJJTimeTwoButtonView.h"

@interface LJJTimeTwoButtonView ()

@end

@implementation LJJTimeTwoButtonView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.singleButton];
        [self addSubview:self.groupButton];
    }
    return self;
}
#pragma mark -
#pragma mark - method
- (void)buttonMethod:(UIButton *)sender
{
    if (self.buttonBlock) {
        self.buttonBlock(sender.tag);
    }
    if (sender.tag == 1000) {
        self.singleButton.selected = YES;
        self.groupButton.selected = NO;
    }
    else
    {
        self.singleButton.selected = NO;
        self.groupButton.selected = YES;
    }
}
#pragma mark -
#pragma mark - lazy method
- (UIButton *)singleButton
{
    if (!_singleButton) {
        _singleButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _singleButton.frame = CGRectMake(0, 0, WIDTH / 2, 50);
        [_singleButton setTitle:@"新品团购" forState:(UIControlStateNormal)];
        [_singleButton setImage:[UIImage imageNamed:@"限时特卖界面新品团购图标未选中"] forState:(UIControlStateNormal)];
        [_singleButton setImage:[UIImage imageNamed:@"限时特卖界面新品团购图标"] forState:(UIControlStateSelected)];
        [_singleButton setTitleColor:RGB(56, 166, 243, 1) forState:(UIControlStateNormal)];
        [_singleButton setTitleColor:RGB(213, 48, 34, 1) forState:(UIControlStateSelected)];
        [_singleButton addTarget:self action:@selector(buttonMethod:) forControlEvents:UIControlEventTouchUpInside];
        _singleButton.tag = 1000;
        _singleButton.selected = YES;
    }
    return _singleButton;
}
- (UIButton *)groupButton
{
    if (!_groupButton) {
        _groupButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _groupButton.frame = CGRectMake(WIDTH/2, 0, WIDTH/2, 50);
        [_groupButton setTitle:@"品牌团购" forState:(UIControlStateNormal)];
        [_groupButton setImage:[UIImage imageNamed:@"限时特卖界面品牌团购图标"] forState:(UIControlStateNormal)];
        [_groupButton setImage:[UIImage imageNamed:@"限时特卖界面品牌团购图标选中"] forState:(UIControlStateSelected)];
        [_groupButton setTitleColor:RGB(56, 166, 243, 1) forState:(UIControlStateNormal)];
        [_groupButton setTitleColor:RGB(213, 48, 34, 1) forState:(UIControlStateSelected)];
        [_groupButton addTarget:self action:@selector(buttonMethod:) forControlEvents:UIControlEventTouchUpInside];
        _groupButton.tag = 1001;
        _groupButton.selected = NO;
    }
    return _groupButton;
}

@end
